package com.xxk.rocket.star.core.annotation;

import com.xxk.rocket.star.core.context.AbsProcessContext;
import com.xxk.rocket.star.core.context.ConsumeContext;
import com.xxk.rocket.star.core.context.ProducerContext;

import java.lang.reflect.Method;

public abstract class AbsProcessAnnotationProducerAndConsume<DTO>
        extends AbsProcessContext<DTO>
        implements
        IProcessAnnotationConsume,
        IProcessAnnotationProducer {

  protected abstract void processConsume(DTO dto, Class aClass, Object o, Method method)
          throws Throwable;

  @Override
  public void processConsumeByContext(ConsumeContext consumeContext, Class aClass, Object o,
                                      Method method) throws Throwable {
    processConsume((DTO) consumeContext.getDTOOrNew(this), aClass, o, method);
  }

  protected abstract void processProducer(DTO dto, Class aClass, Object o, Method method)
          throws Throwable;

  @Override
  public void processProducerByContext(ProducerContext producerContext, Class aClass, Object o,
                                       Method method) throws Throwable {
    processProducer((DTO) producerContext.getDTOOrNew(this), aClass, o, method);
  }

}
